package com.itheima.job.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.Locale;

/**
 * @author LiangTianQi
 * @describe
 * @date 2020/11/16 22:18
 */
public class SpringContextUtil implements ApplicationContextAware {
    private  static ApplicationContext context=null;



    @Override
    @SuppressWarnings("static-access")
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        //TODO Auto-generated method stub
//        this.context = context;
        SpringContextUtil.context = applicationContext;
    }

    public static Object getBean(String beanName) {
        return context.getBean(beanName);
    }

    public static String getMessage(String key) {
        return context.getMessage(key, null, Locale.getDefault());
    }
}
